VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "clsPhoneEntry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'*---------------------------------------------------------------
'*
'* ClassName:      clsPhoneEntry
'* FileName:       PhoneEntry.CLS
'* Date:           July 1998
'* Author:         Ian M. Weatherburn
'* Company:        Mindkey Software Solutions (Pty) Ltd.
'* Copyright:      Copyright (C) 1998 by Mindkey Software Solutions
'*                 All Rights Reserved
'* Description:    RAS Phone Entry Collection
'*
'*---------------------------------------------------------------

Option Explicit

' Phone Entry items
Private strEntryName As String
Private strPhoneNumber As String
Private strCallbackNumber As String
Private strUserName As String
Private strPassword As String
Private strDomain As String
Private intIndex As Integer

' Did the password get fetched?
Private lngGotPassword As Long

Public Property Get EntryName() As String
  EntryName = strEntryName
End Property

Public Property Let EntryName(strNewEntryName As String)
  Dim lngRetCode As Long
  
  If blnAllowUpdate Then
    strEntryName = strNewEntryName
    lngRetCode = fnRASGetEntryDialParams()
    If lngRetCode Then
      Err.Raise vbObjectError + lngRetCode, _
                "EntryName Set Failed", _
                "RAS Failure"
    End If
  Else
    lngRASErrorNumber = 1111
    strRASErrorMessage = "Property not updateable"
    Err.Raise vbObjectError + 1111, _
              "Property not updateable", _
              "RAS Failure"
  End If
End Property

Public Property Get PhoneNumber() As String
  PhoneNumber = strPhoneNumber
End Property

Public Property Let PhoneNumber(strNewPhoneNumber As String)
  Dim lngRetCode As Long
  
  strPhoneNumber = strNewPhoneNumber
  
  lngRetCode = fnRASSetEntryDialParams()
  
  If lngRetCode Then
    Err.Raise vbObjectError + lngRetCode, _
              "PhoneNumber Set Failed", _
              "RAS Failed"
  End If
End Property

Public Property Get CallbackNumber() As String
  CallbackNumber = strCallbackNumber
End Property

Public Property Let CallbackNumber(strNewCallbackNumber As String)
  Dim lngRetCode As Long
  
  strCallbackNumber = strNewCallbackNumber
  
  lngRetCode = fnRASSetEntryDialParams()
  
  If lngRetCode Then
    Err.Raise vbObjectError + lngRetCode, _
              "CallbackNumber Set Failed", _
              "RAS Failed"
  End If
End Property

Public Property Get UserName() As String
  UserName = strUserName
End Property

Public Property Let UserName(strNewUserName As String)
  Dim lngRetCode As Long
  
  strUserName = strNewUserName
  
  lngRetCode = fnRASSetEntryDialParams()
  
  If lngRetCode Then
    Err.Raise vbObjectError + lngRetCode, _
              "UserName Set Failed", _
              "RAS Failed"
  End If
End Property

Public Property Get Password() As String
  Password = strPassword
End Property

Public Property Let Password(strNewPassword As String)
  Dim lngRetCode As Long
  
  strPassword = strNewPassword
  
  lngRetCode = fnRASSetEntryDialParams()
  
  If lngRetCode Then
    Err.Raise vbObjectError + lngRetCode, _
              "Password Set Failed", _
              "RAS Failed"
  End If
End Property

Public Property Get Domain() As String
  Domain = strDomain
End Property

Public Property Let Domain(strNewDomain As String)
  Dim lngRetCode As Long
  
  strDomain = strNewDomain
  
  lngRetCode = fnRASSetEntryDialParams()
  
  If lngRetCode Then
    Err.Raise vbObjectError + lngRetCode, _
              "Domain Set Failed", _
              "RAS Failed"
  End If
End Property

Public Property Get Index() As Integer
  Index = intIndex
End Property

Public Property Let Index(intNewIndex As Integer)
  
  If blnAllowUpdate Then
    intIndex = intNewIndex
  Else
    lngRASErrorNumber = 1111
    strRASErrorMessage = "Property Not Updateable"
    Err.Raise vbObjectError + 1111, _
              "Property Not Updateable", _
              "RAS Failed"
  End If
End Property

Public Function DialEntry(blnAsync As Boolean) As clsConnection

  Set DialEntry = _
    lpConnections.AddConnection( _
      strEntryName, _
      strPhoneNumber, _
      strCallbackNumber, _
      strUserName, _
      strPassword, _
      strDomain, _
      blnAsync)
End Function

Public Sub EditEntry()
  Dim lngRetCode As Long
  
  ' RAS calls up dialog under 95.  This fails on NT.
  lngRetCode = RasEditPhonebookEntry(APINULL, vbNullString, strEntryName)
  If lngRetCode Then
    lngRASErrorNumber = lngRetCode
    strRASErrorMessage = lpRASError.fnRASErrorMessage()
    Err.Raise vbObjectError + lngRetCode, _
              "EditEntry Method Failed", _
              "RAS Failure"
  End If
End Sub

Private Function fnRASGetEntryDialParams() As Long
  Dim lngRetCode As Long
  Dim lngRetlstrcpy As Long
  Dim lpRASDialParams95 As RasDialParams95
  
  lpRASDialParams95.dwSize = 1052
  
  lngRetlstrcpy = lstrcpy(lpRASDialParams95.szEntryName(0), strEntryName)
  
  lngRetCode = RasGetEntryDialParams(vbNullString, lpRASDialParams95, lngGotPassword)
  
  Select Case lngRetCode
    Case RAS_SUCCESS
      strUserName = _
        fnTrimNulls(StrConv(lpRASDialParams95.szUserName, vbUnicode))
      strPhoneNumber = _
        fnTrimNulls(StrConv(lpRASDialParams95.szPhoneNumber, vbUnicode))
      strCallbackNumber = _
        fnTrimNulls(StrConv(lpRASDialParams95.szCallBackNumber, vbUnicode))
        
      If lngGotPassword = 1 Then
        strPassword = _
          fnTrimNulls(StrConv(lpRASDialParams95.szPassword, vbUnicode))
      Else
        strPassword = "Password Not Available"
      End If
      
      strDomain = _
        fnTrimNulls(StrConv(lpRASDialParams95.szDomain, vbUnicode))
        
      fnRASGetEntryDialParams = 0
      
    Case NOT_SUPPORTED
      ' Running Windows NT so set to "Not Available"
      strUserName = "Not Available"
      strPhoneNumber = "Not Available"
      strCallbackNumber = "Not Available"
      strPassword = "Not Available"
      strDomain = "Not Available"
      
      ' Not going to fail on NT, because this is extraneous stuff
      fnRASGetEntryDialParams = 0
      
    Case Else
      strUserName = "Not Available"
      strPhoneNumber = "Not Available"
      strCallbackNumber = "Not Available"
      strPassword = "Not Available"
      strDomain = "Not Available"
      
      lngRASErrorNumber = lngRetCode
      strRASErrorMessage = lpRASError.fnRASErrorMessage()
      
      fnRASGetEntryDialParams = lngRetCode
  End Select
End Function

Private Function fnRASSetEntryDialParams() As Long
  Dim lngRetCode As Long
  Dim lngRetlstrcpy As Long
  Dim lngAttemptOrder As Long
  
  Dim lpRASDialParams95 As RasDialParams95
  
  lpRASDialParams95.dwSize = 1052
  
  lngRetlstrcpy = lstrcpy(lpRASDialParams95.szEntryName(0), strEntryName)
  lngRetlstrcpy = lstrcpy(lpRASDialParams95.szUserName(0), strUserName)
  lngRetlstrcpy = lstrcpy(lpRASDialParams95.szDomain(0), strDomain)
  lngRetlstrcpy = lstrcpy(lpRASDialParams95.szPhoneNumber(0), strPhoneNumber)
  lngRetlstrcpy = lstrcpy(lpRASDialParams95.szCallBackNumber(0), strCallbackNumber)
  
  ' Do not want garbage as password by mistake
  If lngGotPassword = 1 Then
    lngRetlstrcpy = lstrcpy(lpRASDialParams95.szPassword(0), strPassword)
  Else
    lngRetlstrcpy = lstrcpy(lpRASDialParams95.szPassword(0), "")
  End If
  
  lngRetCode = RasSetEntryDialParams(vbNullString, lpRASDialParams95, 0&)
  
  Select Case lngRetCode
    Case RAS_SUCCESS
      strUserName = _
        fnTrimNulls(StrConv(lpRASDialParams95.szUserName, vbUnicode))
      strPhoneNumber = _
        fnTrimNulls(StrConv(lpRASDialParams95.szPhoneNumber, vbUnicode))
      strCallbackNumber = _
        fnTrimNulls(StrConv(lpRASDialParams95.szCallBackNumber, vbUnicode))
        
      If lngGotPassword Then
        strPassword = _
          fnTrimNulls(StrConv(lpRASDialParams95.szPassword, vbUnicode))
      Else
        strPassword = "Not Available"
      End If
      
      strDomain = _
        fnTrimNulls(StrConv(lpRASDialParams95.szDomain, vbUnicode))
        
      fnRASSetEntryDialParams = 0

    Case NOT_SUPPORTED
      ' Running Windows NT so set to "Not Available"
      strUserName = "Not Available"
      strPhoneNumber = "Not Available"
      strCallbackNumber = "Not Available"
      strPassword = "Not Available"
      strDomain = "Not Available"
      
      lngRASErrorNumber = lngRetCode
      strRASErrorMessage = lpRASError.fnRASErrorMessage()
      fnRASSetEntryDialParams = lngRetCode
    
    Case Else
      lngRASErrorNumber = lngRetCode
      strRASErrorMessage = lpRASError.fnRASErrorMessage()
      
      fnRASSetEntryDialParams = lngRetCode
  End Select
End Function

'*---------------------------------------------------------------
'* EOF: clsPhoneEntry
'*---------------------------------------------------------------

